unit UMovVale;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Modelo, DB, DBTables, Grids, DBGrids, StdCtrls, Buttons,
  CheckLst, ExtCtrls, Mask, DBCtrls, UDPTOUteis;

type
  TFMovVale = class(TFModelo)
    qPadraoDESCONTADOVALE: TStringField;
    qPadraoVALORVALE: TFloatField;
    dtmfldPadraoDTVALE: TDateTimeField;
    qPadraoEMPRESA: TIntegerField;
    qPadraoCODPESSOA: TIntegerField;
    qPadraoCODVALE: TIntegerField;
    Lb2: TLabel;
    dbedtVALORVALE: TDBEdit;
    Lb3: TLabel;
    dbedtDTVALE: TDBEdit;
    Lb5: TLabel;
    dbedtCODPESSOA: TDBEdit;
    Lb6: TLabel;
    dbedtCODVALE: TDBEdit;
    EdDescPessoa: TEdit;
    PnlInfo: TPanel;
    procedure qPadraoAfterInsert(DataSet: TDataSet);
    procedure dbedtCODPESSOAExit(Sender: TObject);
    procedure PnlInfoDblClick(Sender: TObject);
    procedure qPadraoAfterScroll(DataSet: TDataSet);
    procedure dbedtCODPESSOADblClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FMovVale: TFMovVale;

implementation

uses UPesqPessoas, UPrincipal;

{$R *.dfm}

procedure TFMovVale.qPadraoAfterInsert(DataSet: TDataSet);
begin
  inherited;

  qPadrao.FieldByName('EMPRESA').AsInteger := Logado.EmpresaCodigo;
  qPadrao.FieldByName('CODVALE').AsInteger := DPTOProximo('VALE');
  qPadrao.FieldByName('DESCONTADOVALE').AsString := 'N';
  PnlInfo.Color := clRed;
  PnlInfo.Caption := 'A Receber';

end;

procedure TFMovVale.dbedtCODPESSOAExit(Sender: TObject);
begin
  inherited;

   EdDescPessoa.Text := '';

  if dbedtCODPESSOA.Text <> '' then
  Begin
    qGenerica.Close;
    qGenerica.SQL.Clear;
    qGenerica.SQL.Add('select PESNOME from PESSOAS '
      + ' where PESCODIGO = ' + QuotedStr(dbedtCODPESSOA.Text)
     );
    qGenerica.Open;
    //
    EdDescPessoa.Text := qGenerica.fieldByName('PESNOME').AsString;
    //
  end;


end;

procedure TFMovVale.PnlInfoDblClick(Sender: TObject);
begin
  inherited;

  if (((qPadrao.State = dsInsert) or (qPadrao.State = dsEdit)) and (qPadrao.FieldByName('DESCONTADOVALE').AsString = 'N')) then
  Begin
    PnlInfo.Color := clGreen;
    PnlInfo.Caption := 'Recebido';
    qPadrao.FieldByName('DESCONTADOVALE').AsString := 'S';
    Exit;
  end;

  if (((qPadrao.State = dsInsert) or (qPadrao.State = dsEdit)) and ((qPadrao.FieldByName('DESCONTADOVALE').AsString = 'S') )) then
  Begin
    PnlInfo.Color := clRed;
    PnlInfo.Caption := 'A Receber';
    qPadrao.FieldByName('DESCONTADOVALE').AsString := 'N';
  end;



end;

procedure TFMovVale.qPadraoAfterScroll(DataSet: TDataSet);
begin
  inherited;
  if qPadrao.FieldByName('DESCONTADOVALE').AsString = 'S' then
  Begin
    PnlInfo.Color := clGreen;
    PnlInfo.Caption := 'Recebido';
  end
  Else
  Begin
    PnlInfo.Color := clRed;
    PnlInfo.Caption := 'A Receber';
  end



end;

procedure TFMovVale.dbedtCODPESSOADblClick(Sender: TObject);
begin
  inherited;
  dbedtCODPESSOA.Text := DPTOChamaPesquisa(FPesqPessoas,TFPesqPessoas,'PESCODIGO', QPadrao, dbedtCODPESSOA.Text);

end;

end.
